package com.shanzmoo.h5.domain.dto;

import com.alibaba.fastjson.JSON;
import com.shanzmoo.base.bean.ValidList;
import com.shanzmoo.db.mall.entity.MallOrderDetailEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 商城订单明细保存信息
 *
 * @author Gzhao 2020/12/25
 */
@Data
@ApiModel("商城订单明细保存信息")
public class MallOrderDetailSaveDTO implements Serializable {

    private static final Long serialVersionUID = 1758L;

    @NotBlank(message = "商品sku不允许为空")
    @ApiModelProperty(name = "商品sku", example = "K60B5N2S11")
    private String sku;

    @NotBlank(message = "商品名称不允许为空")
    @ApiModelProperty(name = "商品名称", example = "测试手机2")
    private String spuName;

    @NotBlank(message = "商品图片不允许为空")
    @ApiModelProperty(name = "商品图片", example = "http://shanzmoo.oss-cn-hangzhou.aliyuncs.com/shanzmoo/mall/images/20201221/T5FEerEKk6P1608556106000.png")
    private String pictureUrl;

    @NotBlank(message = "商品单位不允许为空")
    @ApiModelProperty(name = "商品单位", example = "台")
    private String unit;

    @Min(value = 1,message = "请传入正确的商品数量")
    @NotBlank(message = "商品数量不允许为空")
    @ApiModelProperty(name = "商品数量", example = "2")
    private Integer skuNum;

    @NotBlank(message = "规格属性描述不允许为空")
    @ApiModelProperty(name = "规格属性描述", example = "时尚粉,64g,双核")
    private String attributeDesc;

    @DecimalMin(value = "0.00", message = "请输入正确的商品单价")
    @DecimalMax(value = "10000.00", message = "商品单价超出最大范围")
    @NotNull(message = "商品单价不允许为空")
    @ApiModelProperty(name = "商品单价", example = "99.00")
    private BigDecimal unitPrice;

    public static List<MallOrderDetailEntity> createList(ValidList<MallOrderDetailSaveDTO> orderDetailList) {
        return JSON.parseArray(JSON.toJSONString(orderDetailList), MallOrderDetailEntity.class);
    }

}
